<template>
    <div class="tipBox">
        <el-card>
            <el-row>
                <el-col :span="24" class="tipInfo">
                    <span class="tipUser">{{tipData.fromUserName}}</span>请求添加好友
                </el-col>
                <el-col :span="12">
                    <el-button type="primary" @click="agreeFriend">同意</el-button>
                </el-col>
                <el-col :span="12">
                    <el-button type="danger" @click="rejectFriend">拒接</el-button>
                </el-col>
            </el-row>
        </el-card>
    </div>
</template>

<script>

    import * as $Constants from '../../api/Constants'

    export default {
        name: "addFriendTip",
        props :{
            visible : {
                type: Boolean,
                default : false
            },
            tipData : {
                type : Object,
                required: true,
                default: () => {
                    return {}
                }
            }
        },
        data(){
            return {
                // addFriendTipData:tipData
            }
        },
        methods:{
            agreeFriend(){
                let params = {};
                params.fromUser = this.tipData.toUser;
                params.toUser = this.tipData.fromUser;
                params.msgType = $Constants.MSG_TYPE_AGREE_FRIEND;
                // TODO 这里或许使用HTTP请求处理会更好点
                let chatWebsocket = this.$store.state.chatWebsocket;
                chatWebsocket.send(JSON.stringify(params));
                this.$parent.closeAddFriendTip();
            },
            // 拒绝添加好友
            rejectFriend(){
                let params = {};
                params.fromUser = this.tipData.toUser;
                params.toUser = this.tipData.fromUser;
                params.msgType = $Constants.MSG_TYPE_REJECT_FRIEND;
                // TODO 这里或许使用HTTP请求处理会更好点
                let chatWebsocket = this.$store.state.chatWebsocket;
                chatWebsocket.send(JSON.stringify(params));
                this.$message.success('发送成功');
                this.$parent.closeAddFriendTip();
            }
        }
    }
</script>

<style scoped>
    .tipBox {
        height: 200px;width: 200px;position: fixed;right: 0;bottom: 0
    }
    .tipInfo {
        margin-bottom: 40px;font-size: 18px
    }
    .tipUser {
        font-weight: bold;color: red
    }
</style>
